/*
 * @Author: huangtianyang 916072572@qq.com
 * @Date: 2023-04-19 09:03:25
 * @LastEditors: huangtianyang
 * @LastEditTime: 2023-07-28 11:58:04
 * @FilePath: \cxl-h5\src\pages\personalCenter\message\list\index.ts
 */
import { noticePage } from '@/apis/notice'
import { BasicData } from '@/utils/basicData'
import { ref, reactive } from 'vue'

export default class MessageList extends BasicData {
    //消息数据
    list: any[] = reactive([])
    //下拉刷新
    refreshLoading = ref(false)
    //内容数据刷新
    dataLoading = ref(false)
    //内容结束刷新
    dataFinished = ref(false)
    //分页
    pagination: any = reactive({
        pageNo: 1,
        pageSize: 10
    })
    empty = ref(false)
    noticeType = ['其他消息', '系统消息', '业务消息', '调价信息']
    constructor() {
        super()
    }
    //获取公告消息列表
    getData = (refresh = false) => {
        noticePage(this.pagination.pageNo).then(res => {
            if (this.refreshLoading.value) {
                this.refreshLoading.value = false
            }
            // 加载状态结束
            this.dataLoading.value = false
            if (res.data.value === 200) {
                if (refresh) {
                    this.list.length = 0
                }
                this.list.push(...res.data.data.records)

                if (this.list.length >= res.data.data.total) {
                    this.dataFinished.value = true
                }

                this.empty.value = this.list.length ? false : true
            }
        })
    }
    //刷新方法
    onRefresh = () => {
        console.log('下拉刷新')
        this.refreshLoading.value = true
        this.dataFinished.value = false
        this.dataLoading.value = true
        this.pagination.pageNo = 1
        this.getData(true)
    }
    //加载数据
    onLoad = () => {
        console.log('加载数据')
        this.getData()
    }
    //点击打开详情页面
    onOpenDetailed = (item: any) => {
        this.router.push(`/message/${item.id}`)
    }
    //返回首页
    onOpenDetection = () => {
        this.router.replace('/index')
    }
}
